<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<p:dialog xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:p="http://primefaces.org/ui" 
	modal="true" width="600" height="500" resizable="false" 
	widgetVar="dialogAddCondicaoPagamento" id="dialogCondicaoPagamento" closable="false"
	appendToBody="true">
	
	<link type="text/css" rel="stylesheet" href="../../resources/css/style.css" />
	
	<f:facet name="header">
		<h:outputText value="Cadastrar Condição de pagamento" />
	</f:facet>
	
	<h:form id="formAddCondicaoPagamento" prependId="false">
		<p:messages id="messageFormCondicao"/>
		<h:panelGrid columns="2" style="padding:5px;">
			<h:outputText value="Código" />
			<h:outputText value="Condição de pagamento *" />

			<p:inputText style="width:100px;" disabled="true" value="#{compraBean.newCondicao.id}" />
			<p:inputText style="width:300px;"  value="#{compraBean.newCondicao.condicaoPagamento}" required="true" requiredMessage="Informe a condição de pagamento." maxlength="30"/>
		</h:panelGrid>
		
		<h:panelGrid columns="2" style="padding:5px;">
			<h:outputText value="Forma de pagamento *" />
			<h:outputText value="" />		

			<p:autoComplete id="inputFormaPagamento" var="formaPagamento" value="#{compraBean.newCondicao.formaPagamento}" maxlength="30"
				itemLabel="#{formaPagamento.formaPagamento}" itemValue="#{formaPagamento}" size="50" required="true" requiredMessage="Selecione a forma de pagamento."
				converter="formaPagamentoConverter" completeMethod="#{compraBean.getFormaPagamentoByQuery}">
				<p:ajax event="itemSelect" process="@this inputFormaPagamento"/>
			</p:autoComplete>
			
			<p:commandButton icon="ui-icon-search" style="height:24px;" actionListener="#{compraBean.openDialogListFormaPagamento}" process="@this" title="Selecionar forma de pagamento"/>
		</h:panelGrid>
			
		<h:panelGrid columns="6" style="padding:5px;" id="panelParcelas">
			<h:outputText value="Número"/>
			<h:outputText value="Dias"/>
			<h:outputText value="Percentual"/>
			
			<h:outputText value=""/>
			<h:outputText value=""/>	
			<h:outputText value=""/>				
			
			<p:inputText style="width:120px;" disabled="true" value="#{compraBean.newCondicao.qtdParcelas}"/>

			<p:inputText value="#{compraBean.parcela.dia}"
				style="width:100px;" id="parcelaDia" maxlength="8"
				onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#btAddParcela').click(); }">
				<pe:keyFilter regEx="/[\d]/" />
			</p:inputText>
						
			<pe:inputNumber value="#{compraBean.parcela.percentual}" 
				style="width:100px;" id="parcelaPercentual" maxValue="100" decimalPlaces="2" decimalSeparator=","
				onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#btAddParcela').click(); }" />
							
			<p:commandButton icon="ui-icon-plus" style="height:24px;" actionListener="#{compraBean.addParcela}" update="messageFormCondicao"  title="Adicionar parcela" id="btAddParcelas"/>
			<p:commandButton style="height:24px;" actionListener="#{compraBean.cleanListParcela}" value="Limpar" title="Limpar parcelas"/>
		</h:panelGrid>
		
		<p:dataTable var="parcela" style="padding-top:10px;"
			id="tableParcelas" value="#{compraBean.newCondicao.parcelas}"
			emptyMessage="Não há registros">  
	        <p:column headerText="Número" style="width:100px;"> 				         
	            <h:outputText value="#{parcela.numero}" />  
	        </p:column>  
	  
	        <p:column headerText="Dias" style="width:100px;text-align:center;">  
	            <h:outputText value="#{parcela.dia}"/>
	            <f:facet name="footer">
	            	<h:outputText value="Total" style="float:right;"/>
	            </f:facet>  
	        </p:column> 	
	        
	        <p:column headerText="Percentual" style="width:100px;text-align:center;">  
	            <h:outputText value="#{parcela.percentual}" >
    				<f:convertNumber pattern="##0.00" />
    			</h:outputText>     
	            <f:facet name="footer">
	            	<h:outputText value="#{compraBean.newCondicao.totalPercentual}">
	    				<f:convertNumber pattern="##0.00" />
	    			</h:outputText>   
	    			<h:outputText value="%"/> 
	            </f:facet>
	        </p:column> 
  		</p:dataTable>
		
		<div id="popup-buttons" style="padding-bottom: 10px; padding-top: 30px; text-align: right;">
			<p:commandButton value="Salvar" style="height:28px;" actionListener="#{compraBean.saveCondicaoFromDialog}" update="@this, messageFormCondicao" icon="ui-icon-disk"/>
			<p:commandButton value="Cancelar" style="height:28px;" actionListener="#{compraBean.closeDialogAddCondicaoPagamento}" immediate="true" icon="ui-icon-cancel"/>
		</div>		
	</h:form>
</p:dialog>